Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';


var classifyResultStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=ClassifyResult',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]),
autoLoad:true
}); 


//债项详情
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title:'债项信用信息',
renderTo:"list",
height: 400, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 100px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 130, 
items: 
[ { xtype: 'fieldset', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
           xtype: 'datefield',
			id: 'defaultDate', 
			name: 'defaultDate', 
			fieldLabel: '违约认定日期',
			allowBlank: true,
			editable:false,  
			format : 'Y-m-d' ,
			width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
}
]} 
]},{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'defaultBalance',
	name: 'defaultBalance', 
	fieldLabel: '违约认定日本金余额', 
	emptyText: '必填', 
	blankText: '本金余额不能为空', 
	allowBlank: false, 
	regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
 	regexText:'只能输入整数或小数！' , 
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'defaultInterestSum',
	name: 'defaultInterestSum', 
	fieldLabel: '违约认定日前利息总额', 
	emptyText: '必填', 
	blankText: '利息总额不能为空', 
	allowBlank: false, 
	regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
 	regexText:'只能输入整数或小数！',
	width: 200
		}
]} 
]},


{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
          xtype: 'datefield',
			id: 'classifyDate', 
			name: 'classifyDate', 
			fieldLabel: '风险分类日期',
			allowBlank: true,
			editable:false,  
			format : 'Y-m-d' ,
			width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
		xtype: 'combo', 
 		id : "classifyResult",
              store :classifyResultStore,
              fieldLabel: '风险分类结果',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              mode:'remote', 
              emptyText : '请选择分类结果...',
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'classifyResult'
}
]} 
]},
{layout : "form",
items : [{
	xtype: 'textarea', 
	id:'defaultReason',
	name: 'defaultReason', 
	fieldLabel: '违约认定原因',  
	width: 360,
	height:120
}]} 	
] 
}],
buttonAlign:'right',
buttons: 
[  
	
{ text: '保存', handler: editFunction },
{ text: '下一步', handler: editFunctionAndNext } 
] 
});


//表单加载数据
addForm.form.load({  
	waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'obligation/getDebtInfo.do', 
    method:'post',
    success:function(form,action){	
    },  
    failure:function(form,action){
    			//alert(111);
     			Ext.Msg.confirm("Confirm",'请先添加债项详情',function(bool){
					if(bool=='yes'){
						window.location.href="obligation/addDebtDetail.do";
						return true;
					}
					else{
						return false;	
					}
				}); 
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'obligation/editDebt.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.alert('提示', '编辑成功！'); 
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '编辑失败！'); 
			} 
		}); 
	}
	
}

function editFunctionAndNext(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'obligation/editDebt.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.confirm("Confirm",'保存成功！<br>是否继续添加信用信息?',function(bool){
					if(bool=='yes'){
						window.location.href = "view/obligation/DebtGuaranteeInfo.jsp";
						return true;
					}
					else{
						return false;	
					}
				}); 
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '编辑失败！'); 
			} 
		}); 
	}
	
}
       
}); 